package com.wangqinlei.cowims126.service.impl;

import com.wangqinlei.cowims126.mapper.FeedMapper;
import com.wangqinlei.cowims126.pojo.Feed;
import com.wangqinlei.cowims126.service.FeedService;
import com.wangqinlei.cowims126.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Classname FeedServiceImpl
 * @Description None
 * @Date 2019/7/3 11:45
 * @Created by WDD
 */
@Service
public class FeedServiceImpl implements FeedService {

    @Autowired
    private FeedMapper feedMapper;

    @Override
    public PageBean<Feed> queryPage(Map<String, Object> paramMap) {
        PageBean<Feed> pageBean = new PageBean<>((Integer) paramMap.get("pageno"),(Integer) paramMap.get("pagesize"));

        Integer startIndex = pageBean.getStartIndex();
        paramMap.put("startIndex",startIndex);
        List<Feed> datas = feedMapper.queryList(paramMap);
        pageBean.setDatas(datas);

        Integer totalsize = feedMapper.queryCount(paramMap);
        pageBean.setTotalsize(totalsize);
        return pageBean;
    }

    @Override
    public boolean isFeed(Feed feed) {
        Feed tem = feedMapper.isFeed(feed);
        if(tem != null){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public int addFeed(Feed feed) {
        return feedMapper.addFeed(feed);
    }

    @Override
    public int editFeed(Feed feed) {
        return feedMapper.editFeed(feed);
    }

    @Override
    public int deleteFeed(Integer id) {
        return feedMapper.deleteFeed(id);
    }

    @Override
    public List<Feed> getAll(Feed feed) {
        return feedMapper.getAll(feed);
    }

    @Override
    public boolean isCowId(int id) {
        List<Feed> feedList = feedMapper.isCowId(id);
        if (feedList.isEmpty()){
            return true;
        }else{
            return false;
        }
    }
}
